package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.ArticleBean;
import com.mz.ozy.utils.ScreenUtil;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import java.util.List;

/**
 * Created by Administrator on 2019/3/27.
 */

public class StrategyAdapter extends BaseQuickAdapter<ArticleBean, BaseViewHolder> {
    public StrategyAdapter(@Nullable List<ArticleBean> data) {
        super(R.layout.item_strategy_detail, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ArticleBean item) {
        helper.setText(R.id.tv_strategy_title, item.getTitle());
        helper.setText(R.id.tv_strategy_content, item.getIntroduction());
        helper.setText(R.id.tv_strategy_time, item.getCreated());
        helper.setText(R.id.tv_strategy_readnum, item.getBrowseNum() + "");
        helper.setText(R.id.tv_strategy_likenum, item.getCollNum() + "");

        if (1 == item.getIsCollection()) {
            helper.setImageResource(R.id.iv_strategy_likenum, R.mipmap.icon_find_like_press);
        } else {
            helper.setImageResource(R.id.iv_strategy_likenum, R.mipmap.icon_find_like_normal);
        }

        if (TextUtils.isEmpty(item.getImg1())) {
            GlideUtils.loadImg(mContext, helper.getView(R.id.iv_item_find_dynamics_user), R.mipmap.default_strategy_rect_banner);
        } else {
            GlideUtils.loadBackImg(mContext, helper.getView(R.id.iv_item_find_dynamics_user), item.getImg1(), R.mipmap.default_strategy_rect_banner);
        }

        View rootView = helper.getView(R.id.item_root_view);
        int adapterPosition = helper.getAdapterPosition() - getHeaderLayoutCount();
        if (adapterPosition == getData().size() - 1) {
            helper.setGone(R.id.view_strategy_divider, false);
            rootView.setPadding(rootView.getPaddingLeft(), rootView.getPaddingTop(), rootView.getPaddingRight(), ScreenUtil.dip2px(mContext, 20));
        } else {
            helper.setVisible(R.id.view_strategy_divider, true);
            rootView.setPadding(rootView.getPaddingLeft(), rootView.getPaddingTop(), rootView.getPaddingRight(), ScreenUtil.dip2px(mContext, 15));
        }
        helper.addOnClickListener(R.id.item_root_view);
        helper.addOnClickListener(R.id.ll_strategy_likenum);
    }
}
